import 'package:boss/provider/table_provider.dart';
import 'package:boss/ui/page/tableManagement/page/tableDetail/provider/table_detail_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TableDetailFooter extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<TableDetailProvider>(
      builder: (context, tableDetailProvider, _) {
        return FixedBottomBtn(
          title: '保 存',
          isShowShadow: false,
          onTap: () => tableDetailProvider.isUpdate ? _updateStoreTable(context) : _plusStoreTable(context),
        );
      },
    );
  }

  _plusStoreTable(BuildContext context) async {
    var tableProvider = Provider.of<TableProvider>(
      context,
      listen: false,
    );
    var tableDetailProvider = Provider.of<TableDetailProvider>(
      context,
      listen: false,
    );

    var result = await tableProvider.plusStoreTable(tableDetailProvider.storeTable);
    if (result) Navigator.pop(context);
  }

  _updateStoreTable(BuildContext context) async {
    var tableProvider = Provider.of<TableProvider>(
      context,
      listen: false,
    );
    var tableDetailProvider = Provider.of<TableDetailProvider>(
      context,
      listen: false,
    );

    var result = await tableProvider.updateStoreTable(tableDetailProvider.storeTable);
    if (result) Navigator.pop(context);
  }
}
